package com.whfc.mach.manager.strategy.work;

import com.whfc.mach.dto.AppMachDaySegDTO;
import com.whfc.mach.enums.WorkState;
import com.whfc.mach.manager.util.MachSegmentUtil;
import com.whfc.mach.manager.util.MachUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * @Description: 打桩机的工时策略(全部怠速 - > 工作)
 * @author: xugcheng
 * @version: 1.0
 * @date: 2020-12-11 15:23
 */
public class DzjWorkStrategy implements WorkStrategy {

    private Logger logger = LoggerFactory.getLogger(DzjWorkStrategy.class);

    @Override
    public Integer amend(Integer workState) {
        //打桩机:怠速->工作
        if (MachUtil.isIdleState(workState)) {
            return WorkState.RUN.getValue();
        }
        return workState;
    }

    @Override
    public List<AppMachDaySegDTO> amend(List<AppMachDaySegDTO> segmentList) {

        //怠机全部修改成工作
        for (AppMachDaySegDTO segDTO : segmentList) {
            if (MachUtil.isIdleState(segDTO.getWorkState())) {
                segDTO.setWorkState(WorkState.RUN.getValue());
            }
        }
        //合并相同分段
        List<AppMachDaySegDTO> amendSegList = MachSegmentUtil.mergeMachDaySegment(segmentList);
        logger.info("全部怠机转换成工作,{}->{}", segmentList.size(), amendSegList.size());
        return amendSegList;
    }
}
